Weed out empty features from the registry
authorAlex Crichton <alex@alexcrichton.com>
Tue, 21 Jul 2015 17:16:15 +0000 (10:16 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 21 Jul 2015 17:35:13 +0000 (10:35 -0700)
It looks like the empty string is leaking in as a feature to all crates being
published on crates.io unintentionally. This means that each dependency edge
activates the feature `""`. This in turn confuses the resolution process quite a
bit, causing it to be far more recursive than it should be.

The empty feature, `""`, is weeded out during activation of features but it's
never explicitly activated. This means that each new dependency we see has one
requested feature (the empty one) with no activated features (as it doesn't have
any). This ends up causing us to recurse to attempt to reactivate the
dependency. This extreme recursion ended up blowing the stack on some smaller
crates and this commit fixes that.

src/cargo/sources/registry.rs

index 6dfdfcf6012cb0cabad5ca75a2e9db1183707471..bda2de90eb5389dfd6f69d849bf5dbcfa130b81b 100644 (file)
@@ -438,6 +438,13 @@ impl<'cfg> RegistrySource<'cfg> {
             _ => Kind::Normal,
         };
 
+        // Unfortunately older versions of cargo and/or the registry ended up
+        // publishing lots of entries where the features array contained the
+        // empty feature, "", inside. This confuses the resolution process much
+        // later on and these features aren't actually valid, so filter them all
+        // out here.
+        let features = features.into_iter().filter(|s| !s.is_empty()).collect();
+
         Ok(dep.set_optional(optional)
               .set_default_features(default_features)
               .set_features(features)